#include <iostream>
#include <Windows.h>
#include <xnamath.h>

using namespace std;

ostream &operator<<(ostream &os, FXMVECTOR v) {
	XMFLOAT3 dest;
	XMStoreFloat3(&dest, v);
	os << "(" << dest.x << ", " << dest.y << ", " << dest.z << ")";
	return os;
}



void tryXNAMath() {
	FLOAT x = 3.141;
	XMFLOAT3 fs = { x,2,3 };
	XMVECTOR v = XMLoadFloat3(&fs);
	std::cout << XMVectorGetX(v) << std::endl;

	const XMVECTORF32 vv = { 1,XM_PIDIV2,3,4 };
	std::cout << XMVectorGetY(vv) << std::endl;
}

void useXM() {
	cout.setf(ios_base::boolalpha);
	if (!XMVerifyCPUSupport()) {
		cout << "xna math not supported" << endl;
		return;
	}
	//XMVECTOR p = XMVectorZero();
	//XMVECTOR q = XMVectorSplatOne();
	//XMVECTOR u = XMVectorSet(1.0f, 2.0f, 3.0f, .0f);
	//XMVECTOR v = XMVectorReplicate(-2.0f);
	//XMVECTOR w = XMVectorSplatZ(u);

	//cout << "p = " << p << endl;
	//cout << "q = " << q << endl;
	//cout << "u = " << u << endl;
	//cout << "v = " << v << endl;
	//cout << "w = " << w << endl;
	
	XMVECTOR n = XMVectorSet(1.0f, .0f, .0f, .0f);
	XMVECTOR u = XMVectorSet(1.0f, 2.0f, 3.0f, .0f);
	XMVECTOR v = XMVectorSet(-2.0f, 1.0f, -3.0f, .0f);
	XMVECTOR w = XMVectorSet(.707f, .707f, .0f, .0f);

	auto a = u + v;
	auto b = u - v;
	auto c = 10.0f * u;
	auto L = XMVector3Length(u);
	auto d = XMVector3Normalize(u);
	auto s = XMVector3Dot(u, v);
	auto e = XMVector3Cross(u, v);

	XMVECTOR projW;
	XMVECTOR perpW;
	XMVector3ComponentsFromNormal(&projW, &perpW, w, n);
	bool equal = XMVector3Equal(projW + perpW, w) != 0;
	bool notEqual = XMVector3NotEqual(projW + perpW, w) != 0;

	XMVECTOR angleVec = XMVector3AngleBetweenVectors(projW, perpW);
	float angleRadians = XMVectorGetX(angleVec);
	float angleDegree = XMConvertToDegrees(angleRadians);

	cout << "u = " << u << endl;
	cout << "v = " << v << endl;
	cout << "w = " << w << endl;
	cout << "n = " << n << endl;
	cout << "a = u + v = " << a << endl;
	cout << "b = u - v = " << b << endl;
	cout << "c = 10 * u = " << c << endl;
	cout << "d = u / ||u|| = " << d << endl;
	cout << "e = u x v = " << e << endl;
	cout << "L = ||u|| = " << L << endl;
	cout << "s = u.v = " << s << endl;
	cout << "projW = " << projW << endl;
	cout << "perpW = " << perpW << endl;
	cout << "projW + perpW == W = " << equal << endl;
	cout << "projW + perpW != W = " << notEqual << endl;
	cout << "angle = " << angleDegree << endl;

	return;

}


int main() {
	//tryXNAMath();
	useXM();
}